<?
Class CoreModel extends CI_Model{
	public function __construct(){
		parent::__construct();
	}
	public function Execute($table,$one=false){
		$query = $this->db->get($table);
		if($query->num_rows() > 0 ){
			$data = $query->result();
			if($one){
				return $data[0];
			}return $data;
		}
		return false;
	}
	public function insertLog($data) {
		
		$data['log_date'] = date("Y-m-d H:i:s");
		$data['log_ip'] = $_SERVER['REMOTE_ADDR'];
		$this->db->insert('import_log',$data);
	}
	public function insertLogFailed($func,$table,$page){
		return $this->insertLogData($func,$table, 0,$page,"FAILED");
	}
	public function insertLogComplete($func,$table,$row,$page){
		return $this->insertLogData($func,$table, $row,$page,"COMPLETED");
	}
	public function insertLogData($func,$table,$row,$page,$status){
		$data_log['log_function'] = $func;
		$data_log['log_table'] = $table;
		$data_log['log_record'] = $row;
		$data_log['log_type'] = "INSERT";
		$data_log['log_status'] = $status;
		$data_log['log_by_name'] = "Batch Job";
		$data_log['log_page'] = $page;
		return $this->insertLog($data_log);
	}
	public function convertValue($value){
    	$pos = strpos($value, "-"); //หา - ใน $value
    	if ($pos == false) {
        	return $value;
    	} else {
        	return str_replace("-", "", $value) *-1;  //แทนที่ - ด้วย "" แล้วคูณค่าด้วย -1 จะได้ค่าติดลบที่สามารถเก็บลง mysql ได้
    	}
	}
	 
}
?>